/*
============================================================================
 Name        : StreamPlayer.cpp
 Author      : 
 Version     :
 Copyright   : Your copyright notice
 Description : CStreamPlayer implementation
============================================================================
*/

#include "StreamPlayer.h"
#include "StreamReader.h"
#include "StreamWriter.h"
#include "PluginUtility.h"

EXPORT_C CStreamPlayer::CStreamPlayer()
: iStreamBuffer(NULL), iStreamReader(NULL), iStreamWriter(NULL)
{
}

EXPORT_C CStreamPlayer::~CStreamPlayer()
{
	DELETE(iStreamBuffer);
	DELETE(iStreamWriter);
	DELETE(iStreamReader);
}

EXPORT_C void CStreamPlayer::ConstructL()
{
	//Create stream buffer
	iStreamBuffer = new (ELeave)CStreamBuffer();
	CleanupStack::PushL(iStreamBuffer);

	//Construct buffer
	iStreamBuffer->ConstructL();
	CleanupStack::Pop();
}

EXPORT_C void CStreamPlayer::SetReaderL(CStreamReader* aStreamReader)
{
	iStreamReader = aStreamReader;
	iStreamReader->SetStreamBuffer(iStreamBuffer);
}

EXPORT_C void CStreamPlayer::SetWriterL(CStreamWriter* aStreamWriter)
{
	iStreamWriter = aStreamWriter;
	iStreamWriter->SetStreamBuffer(iStreamBuffer);
}

EXPORT_C void CStreamPlayer::StartL(const TDesC& aUrlRequest)
{
	iStreamBuffer->Start();

	//Start reader
	iStreamReader->SetUrl(aUrlRequest);
	iStreamReader->StartL();

	//Start writer
	iStreamWriter->StartL();
}

EXPORT_C void CStreamPlayer::StopL()
{
	iStreamWriter->Cancel();
}

EXPORT_C TInt CStreamPlayer::Volume()
{
	return iStreamWriter->Volume();
}

EXPORT_C void CStreamPlayer::SetVolume(TInt aVolume)
{
	iStreamWriter->SetVolume(aVolume);
}